<?php

namespace app\admin\controller;
use app\BaseController;
use think\facade\Db;

class User extends BaseController {

  public function list() {
    $request = request()->param();

    //分页查询
    $page = pageQuery($request);

    $list = Db::table('user_account')->order('id', 'desc')->page($page['page'], $page['count'])->select();
    if (!$list) {
      returnJson(-2, '查询失败！');
    }
    $count = Db::table('user_account')->count(); //总条数
    
    $data = [
      'count' => $page['count'],
      'total' => $count,
      'rows' => $list,
    ];
    
    returnJson(0, '成功！', $data);
  }


  public function update_pwd (){
    $request = request()->param();
    if (empty($request['password']) || empty($request['id'])) {
      returnJson(-2, '参数错误');
    }

    $id = $request['id'];
    $data = [
      'password' => md5($request['password']),
    ];
    
    $update = Db::table('user_account')->where('id', $id)->update($data);
    if ($update >= 0) {
      returnJson(0, '修改成功！');
    }
    returnJson(-2, '修改失败！');
  }



}